package com.cxg.allsys.adminsys.service.impl;

import com.cxg.allsys.adminsys.mapper.ExpertMapper;
import com.cxg.allsys.adminsys.pojo.Expert;
import com.cxg.allsys.adminsys.service.IExpertService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Data
@Service
public class ExpertService implements IExpertService {
    Logger logger = LoggerFactory.getLogger("ExpertService:"+ExpertService.class);
    @Autowired
    private ExpertMapper expertMapper;
    //分页查询
    @Override
    public List<Expert> query(Integer pageIndex, Integer pageSize, String querStr) {
        log.info("service 分页查询 操作");
        log.info("打印输入的值："+"当前页："+pageIndex+"每页显示条数："+pageSize+"查询条件(专家名字)："+querStr);
        return expertMapper.select(pageIndex, pageSize, querStr);
    }
    //根据专家ID查询
    @Override
    public Expert selectById(Integer expertId) {
        log.info("service 根据专家ID查询 操作");
        log.info("打印输入的值："+"查询条件(专家ID)："+expertId);
        return expertMapper.selectById(expertId);
    }
    //添加专家
    @Override
    public boolean save(Expert expert) {
       log.info("service save 方法实现类");
        try {
            logger.debug("service save 对象正常注入获取");
            log.info("输入内容打印："+expert.toString());
            expertMapper.insert(expert);
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage());
            return false;
        }
    }
    //修改专家信息
    @Override
    public boolean updateExpert(Expert expert) {
        log.info("service updateExpert 方法实现类");
        try {
            logger.debug("service updateExpert 对象正常注入获取");
            log.info("输入内容打印："+expert.toString());
            expertMapper.update(expert);
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage());
            return false;
        }
    }
    //专家状态重置
    @Override
    public boolean updateExpertForEditStatus(Integer expertId,String status) {
        log.info("service updateExpertForEditStatus 方法实现类");
        try {
            logger.debug("service updateExpertForEditStatus 对象正常注入获取");
            log.info("service层输入内容打印："+"ID:"+expertId+"状态："+status);
            expertMapper.updateExpertForEditStatus(expertId,status);
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage());
            return false;
        }
    }
    //删除专家信息
    @Override
    public boolean deleteExpert(Expert expert) {
        log.info("service delectExpert 方法实现类");
        try {
            logger.debug("service delectExpert 对象正常注入获取");
            log.info("输入内容打印："+expert.toString());
            expertMapper.deleteExpert(expert);
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage());
            return false;
        }
    }
}
